import {Component, OnInit} from '@angular/core';
import {GlobalService} from '../../service/GlobalService';
import {Constant} from '../../util/Constant';
import {ModelRes} from '../../entity/ModelRes';
import {NzModalService} from 'ng-zorro-antd';
import {AdminDetailComponent} from './admin-detail/admin-detail.component';

@Component({
  selector: 'app-admin',
  templateUrl: './admin.component.html',
  styleUrls: ['./admin.component.css']
})
export class AdminComponent implements OnInit {

  dataList = [];
  type = 1;
  key = '';
  customerKey;
  customerValue;

  constructor(public app: GlobalService, public modalService: NzModalService) {
  }

  ngOnInit() {

    this.getList();

  }


  getList() {
    const obj = {'page': 1, 'size': 20, 'adminName': '', 'adminPhone': '', 'shopId': 0};

    this.app.req(Constant.ADMIN_LIST, obj).then((json: ModelRes) => {
      this.dataList = json.data.list;
    });

  }

  del(data) {
    this.app.toast('删除成功');
  }

  update(data) {
    // const obj = {'adminid': data.adminid};
    // this.app.req(Constant.ADMIN_UPDATE, obj).then((json: ModelRes) => {
    //   this.getList();
    // });

    const modal = this.modalService.create({
      nzTitle: '详情',
      nzContent: AdminDetailComponent,
      nzComponentParams: {'obj': data},
      nzFooter: [{
        label: '确认',
        shape: 'primary',
        loading: false,
        onClick: (c) => {
          c.update();
        }
      }]
    });

    this.modalService.afterAllClose.subscribe(() => {
      this.getList();
    });
  }

  onSelect(e) {
    console.log(e);
  }

  onSelectKey(e) {
    this.customerKey = e.id;
    this.customerValue = e.value;

    console.log(e.id + '=' + e.value);

  }

  getKey(e) {
    console.log(e);
  }


  build() {
  }

}
